package com.luzhikun.kickUser;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;
import java.util.Map;

public class KickServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        // 获取全局域
        ServletContext sc = request.getServletContext();
        // 从全局域中获取map
        Map<String, HttpSession> map = (Map<String, HttpSession>) sc.getAttribute("map");

        // 获取请求参数
        String name = request.getParameter("name");
        // 从map中获取当前用户所对应的Session
        HttpSession session = map.get(name);
        // 使Session失效
        session.invalidate();

        // 从map中删除这个session
        map.remove(name);
        // 返回index页面
        request.getRequestDispatcher("/index.jsp").forward(request, response);

    }


}
